import cloud from '@lafjs/cloud'
let dbName = "web-order"

export async function changeOrderStatus(orderId) {
  let { curriculum_id, status } = await cloud.nw.db.findByWhereJson({
    dbName: "web-order",
    whereJson: { _id: orderId },
  });

  let { type } = await cloud.nw.db.findByWhereJson({
    dbName: "web-course",
    whereJson: { _id: curriculum_id },
  });

  let resp = await cloud.nw.db.findByWhereJson({
    dbName: "web-curriculum",
    whereJson: { _id: type[0] },
  });

  //待支付
  if (status == 0) {
    let state
    if (resp.hasOwnProperty("isExamine") && resp.isExamine == 1) {  //需要审核
      state = 1
    } else {
      state = 2  //报名成功
    }
    //更新订单信息
    await cloud.nw.db.update({
      dbName, whereJson: { _id: orderId }, dataJson: { status: state }
    });
  } else if (status == 8) {
    await cloud.nw.db.update({
      dbName, whereJson: { _id: orderId }, dataJson: { status: 2 }
    });
  }
}
